package com.et114.modules.order.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.et114.core.action.BaseDispatchAction;
import com.et114.core.common.CONST;
import com.et114.modules.cust.BIZ;
import com.et114.modules.cust.services.IMng_CustService;
import com.et114.modules.cust.services.Mng_CustServiceImp;
import com.et114.modules.order.form.OrderForm;
import com.et114.modules.order.service.IMng_OrderService;
import com.et114.modules.order.service.Mng_OrderServiceImp;
import com.et114.modules.order.vo.OrderTrack;
import com.et114.modules.order.vo.OrderVO;
import com.et114.modules.org.services.UserManager;
import com.et114.modules.org.utility.SessionUserInfo;
import com.et114.modules.org.vo.UserVo;
import com.et114.modules.products.commons.Const;
import com.et114.modules.system.dictionary.DictionaryCache;
import com.et114.modules.system.dictionary.vo.BizOption;

/**
 * 货运订单
 * @author zhiweip
 * @version 1.0
 * @created 09-十一月-2010 23:03:48
 */
public class Mng_LgiOrderAction  extends BaseDispatchAction {
	
	private IMng_OrderService mng_OrderService = ( Mng_OrderServiceImp )getBean ( "mng_OrderService" ) ;
	private IMng_CustService mng_CustService	= ( Mng_CustServiceImp ) getBean ( "mng_CustService" );
	
	@ Override
	public ActionForward unspecified ( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		request.setAttribute ( "OPTIONS" , mng_CustService.getItemTypes ( ) ) ;
		DictionaryCache bean = DictionaryCache.getInstance ( ); 
		List < BizOption > options = bean.listBizOptions (
				"LGICOM", false , CONST.COUNTRY_ZH );
		
		request.setAttribute ( "LGICOM" , options);
		return mapping.findForward ( "queryOrderDataList" ) ;
	}


	//Mng_CustForm
	public ActionForward orderQuery ( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		request.setAttribute ( "OPTIONS" , mng_CustService.getItemTypes ( ) ) ;
		DictionaryCache bean = DictionaryCache.getInstance ( ); 
		List < BizOption > options = bean.listBizOptions (
				"LGICOM", false , CONST.COUNTRY_ZH );
		
		request.setAttribute ( "LGICOM" , options);
		OrderForm cform=(OrderForm)form; 
		
		OrderTrack vo=cform.getOrd ( );
		vo.setPageNum ( cform.getPageNum ( ) );
		vo.setPageSize ( cform.getPageSize ( ) );
		
		UserManager userManager = ( UserManager )getBean ( "userManager" ) ;
		UserVo user= new UserVo();
		user.setPageSize ( 10000 );
		request.setAttribute ( "EMPLYS" , ((com.et114.modules.cust.dao.Mng_CustDaoImp)getBean("mng_CustDao")).query_AllEmpList(null));
		request.setAttribute ( "ord" , vo );
		vo.setOrderstate ( BIZ.ORDER_OK );
		vo.setIsaudi (BIZ.AUDI_PASS);//已审核
		vo.setIstosup ( BIZ.ORD_ISTOSUP_YES );
		request.setAttribute ( "DataList",mng_OrderService.queryOrderDataList ( vo ));
		return mapping.findForward ( "queryOrderDataList" ) ; 
	}
	
	public ActionForward toUpdateInfo( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		
		OrderForm cform=(OrderForm)form; 
		
		OrderTrack vo=cform.getOrd ( );

		String orderids=request.getParameter (  "ordids" );
		 
		UserManager userManager = ( UserManager )getBean ( "userManager" ) ;
		UserVo user= new UserVo();
		user.setPageSize ( 10000 );
		request.setAttribute ( "EMPLYS" , ((com.et114.modules.cust.dao.Mng_CustDaoImp)getBean("mng_CustDao")).query_AllEmpList(null));
		
		DictionaryCache bean = DictionaryCache.getInstance ( ); 
		List < BizOption > options = bean.listBizOptions (
				"LGICOM", false , CONST.COUNTRY_ZH );
		
		request.setAttribute ( "LGICOM" , options);
		
		String [] ids=orderids.split ( ";" );
		if(ids.length==1){
			vo.setOrderid ( new Integer(ids[0]) );
			request.setAttribute ( "ord" , mng_OrderService.loadOrderTrackBy_Orderid ( vo ));
		}else{
//			vo.setOrderids ( ids );
//			Long c=mng_OrderService.countIstoSup ( vo );
//			if(c.intValue ( )>0){
//				request.setAttribute ( "INFO" ,"");
//			}
		}
		
		request.setAttribute ( "ORDERIDS" , orderids );
		return mapping.findForward ( "toupdateinfo" ) ; 
	}
	
	public ActionForward updateInfo( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		
		OrderForm cform=(OrderForm)form; 
		
		OrderTrack vo=cform.getOrd ( );
		SessionUserInfo sessionuserinfo=getCurrentUser(request);
		vo.setUpdtUser ( sessionuserinfo.getUserId ( ) );
		
		String orderids=request.getParameter (  "ordids" );
		mng_OrderService.updateLgiOrder ( vo , orderids );
		
		
		request.setAttribute ( "SAVEFLAG" , "OK" );
		
		return mapping.findForward ( "toupdateinfo" ) ; 
	}
	
	public ActionForward toUpdateInfo_Arr( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		
		OrderForm cform=(OrderForm)form; 
		
		OrderTrack vo=cform.getOrd ( );

		String orderids=request.getParameter (  "ordids" );
		 
		UserManager userManager = ( UserManager )getBean ( "userManager" ) ;
		UserVo user= new UserVo();
		user.setPageSize ( 10000 );
		request.setAttribute ( "EMPLYS" , ((com.et114.modules.cust.dao.Mng_CustDaoImp)getBean("mng_CustDao")).query_AllEmpList(null));
		
		String [] ids=orderids.split ( ";" );
		if(ids.length==1){
			vo.setOrderid ( new Integer(ids[0]) );
			request.setAttribute ( "ord" , mng_OrderService.loadOrderTrackBy_Orderid ( vo ));
		}
		
		request.setAttribute ( "ORDERIDS" , orderids );
		return mapping.findForward ( "toupdateinfo_arr" ) ; 
	}
	
	public ActionForward updateInfo_Arr( ActionMapping mapping ,
			ActionForm form , HttpServletRequest request ,
			HttpServletResponse response ) throws Exception {
		
		OrderForm cform=(OrderForm)form; 
		
		OrderTrack vo=cform.getOrd ( );
		SessionUserInfo sessionuserinfo=getCurrentUser(request);
		vo.setUpdtUser ( sessionuserinfo.getUserId ( ) );
		
		String orderids=request.getParameter (  "ordids" );
		mng_OrderService.updateLgiOrder_Arr ( vo , orderids );
		
		
		request.setAttribute ( "SAVEFLAG" , "OK" );
		
		return mapping.findForward ( "toupdateinfo" ) ; 
	}
		
	

}